﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
    public static class CustomExtentions
    {
        public static bool ContainsBytes(this byte[] _bufferSum, ref byte[] sequence)
        {
            int currOffset = 0;

            int position = 0;

            for (position = 0; position < _bufferSum.Length; position++)
            {
                byte b = _bufferSum[position];
                if (b == sequence[currOffset])
                {
                    if (currOffset == sequence.Length - 1)
                    {
                        return true;
                    }
                    currOffset++;
                    continue;
                }

                // Fixup the offset to the byte after the beginning of the abortive sequence
                if (currOffset == 0) continue;
                position -= currOffset;
                currOffset = 0;
            }

            return false;
        }

        public static string ToUpperFirstLetter(this string source)
        {
            if (string.IsNullOrEmpty(source))
                return string.Empty;
            // convert to char array of the string
            char[] letters = source.ToCharArray();
            // upper case the first char
            letters[0] = char.ToUpper(letters[0]);
            // return the array made of the new char array
            return new string(letters);
        }
    }
}
